package com.yycx.module.bus.provider.controller;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.security.OpenUser;
import com.yycx.common.springmvc.base.BaseController;
import com.yycx.module.bus.client.entity.BusCustom;
import com.yycx.module.bus.provider.service.BusCustomService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 购货方控制器
 *
 * @author flyme
 * @date 2020-08-01
 */
@RestController
@RequestMapping("/bus/custom/")
public class BusCustomController extends BaseController<BusCustomService, BusCustom> {


    @ApiOperation(value = "购货方-分页列表", notes = "购货方分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "购货方-列表", notes = "购货方列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "购货方-列表", notes = "购货方列表")
    @GetMapping(value = "listByName")
    public ResultBody listByName(@RequestParam(required = false) String keyword) {
        List<BusCustom> list = bizService.listByName(keyword);
        return ResultBody.ok(list);
    }

    @ApiOperation(value = "购货方-省份列表", notes = "购货方列表")
    @GetMapping(value = "areaList")
    public ResultBody areaList() {
        List<EntityMap> list = bizService.selectAreaName();
        return ResultBody.ok(list);
    }

    @ApiOperation(value = "购货方-添加", notes = "添加购货方")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "购货方-更新", notes = "更新购货方")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "购货方-删除", notes = "删除购货方")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "购货方-详情", notes = "购货方详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

    @ApiOperation(value = "更新购货方", notes = "更新购货方")
    @PostMapping(value = "setAllowJs")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "ids", required = true, value = "主键", paramType = "form"),
        @ApiImplicitParam(name = "allowJs", required = true, value = "状态值", paramType = "form")
    })
    public ResultBody setAllowJs(@RequestParam(required = false) Map map, @RequestParam(value = "allowJs") Integer allowJs) {
        return bizService.setState(map, "allowJs", allowJs);
    }


    @ApiOperation(value = "更新购货方", notes = "更新购货方")
    @PostMapping(value = "setCustomState")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "ids", required = true, value = "主键", paramType = "form"),
        @ApiImplicitParam(name = "customState", required = true, value = "状态值", paramType = "form")
    })
    public ResultBody setCustomState(@RequestParam(required = false) Map map, @RequestParam(value = "customState") Integer customState) {
        return bizService.setState(map, "customState", customState);
    }


    @ApiOperation(value = "同步海鹰数据", notes = "同步海鹰数据")
    @PostMapping(value = "syncHyData")
    public ResultBody syncHyData() {
        OpenUser openUser = OpenHelper.getUser();
        bizService.syncHyData(openUser);
        return ResultBody.msg("同步请求已提交,请稍后刷新查看,请勿重复提交");
    }

    @ApiOperation(value = "同步海鹰数据", notes = "同步海鹰数据")
    @PostMapping(value = "syncCustomAddress")
    public ResultBody syncCustomAddress(String customCode) {
        bizService.syncCustomAddress(customCode);
        return ResultBody.msg("同步请求已提交,请稍后刷新查看,请勿重复提交");
    }

    @ApiOperation(value = "查询海鹰客商资料", notes = "查询海鹰商品")
    @GetMapping(value = "selectTop20HyCustomList")
    public ResultBody selectTop10HyList(String title) {
        List<EntityMap> list = bizService.selectTop20HyCustomList(title);
        return ResultBody.ok(list);
    }

}
